package edu.tongji.engine.service;

import java.util.Set;

import edu.tongji.engine.common.Log;
import edu.tongji.engine.db.dao.DAOFactory;
import edu.tongji.engine.db.dao.IActorDao;
import edu.tongji.engine.db.pojo.Actor;
import edu.tongji.engine.db.pojo.Task;

public class ActorService {

	private IActorDao dao;
	
	public ActorService(){
		dao = DAOFactory.createActorDao();
	}
	
	public boolean createActor(Actor actor){
		try{
			dao.saveActor(actor);
			return true;
			
		}catch(Exception e){
			e.printStackTrace();
			Log.getLoger().loger.error("save actor Error", e);
			return false;
		}
	}
	
	public boolean deleteActor(Actor actor){
		try{
			dao.deleteActor(actor);
			return true;
			
		}catch(Exception e){
			e.printStackTrace();
			Log.getLoger().loger.error("delete actor Error", e);
			return false;
		}
	}
	
	public boolean modifyActor(Actor actor){
		try{
			dao.saveActor(actor);
			return true;
			
		}catch(Exception e){
			e.printStackTrace();
			Log.getLoger().loger.error("modify actor Error", e);
			return false;
		}
	}
	
	public Actor getActor(Long id){
		return dao.getActor(id);
	}
	
	public Actor getActor(String name){
		return dao.getActor(name);
	}
	
	public boolean sendEmail(Long actorId){
		return false;
	}
	
	public Set<Task> getTaskByActorId(Long id){
		Actor actor = dao.getActor(id);
		return actor.getTasks();
	}
	
	public Set<Task> getTaskByActorName(String name){
		Actor actor = dao.getActor(name);
		return actor.getTasks();
	}
}
